# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgbase=ibus
pkgname=(ibus libibus)
pkgver=1.5.25
pkgrel=3
pkgdesc="Next Generation Input Bus for Linux"
arch=('x86_64')
url="https://github.com/ibus/ibus/wiki"
license=('LGPL')
depends=('dconf' 'gtk3' 'hicolor-icon-theme' 'libnotify' 'python-dbus' 'python-gobject'
         'iso-codes' 'librsvg')
makedepends=('gobject-introspection' 'vala' 'intltool' 'gnome-common' 'gtk-doc' 'gtk4' 'gtk2'
             'qt5-base' 'unicode-cldr' 'unicode-character-database' 'unicode-emoji' 'git')
options=('!emptydirs')
_commit=cfb263f04f82a83dd94f6eedcd5017d40a4a1a05  # 1.5.25
source=("git+https://github.com/ibus/ibus#commit=$_commit")
sha512sums=('SKIP')

pkgver() {
  cd ibus
  git describe --tags | sed 's/-/+/g'
}

prepare() {
  cd ibus
  sed -i 's|$(libibus) $(libibus_emoji_dialog)|$(libibus_emoji_dialog) $(libibus)|' ui/gtk3/Makefile.am
  git cherry-pick -n 936a0e76df79d92a8bdc03e9205330fb84a2083e
  NOCONFIGURE=1 ./autogen.sh
}

build() {
  cd ibus
  ./configure \
    --prefix=/usr \
    --libexecdir=/usr/lib/ibus \
    --sysconfdir=/etc \
    --enable-dconf \
    --enable-wayland \
    --enable-gtk-doc \
    --enable-gtk4 \
    --disable-memconf \
    --enable-ui \
    --disable-python2 \
    --with-python=python3 \
    --with-ucd-dir=/usr/share/unicode/
  sed -i 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package_ibus() {
  depends+=("libibus=$pkgver")

  cd ibus
  make DESTDIR="$pkgdir" install
  make -C src DESTDIR="$pkgdir" uninstall
  make -C bindings DESTDIR="$pkgdir" uninstall
  make DESTDIR="$pkgdir" uninstall-pkgconfigDATA
}

package_libibus() {
  pkgdesc="IBus support library"
  depends=(libg{lib,object,io}-2.0.so)
  provides=('libibus-1.0.so')

  cd ibus
  make -C src DESTDIR="$pkgdir" install
  make -C bindings DESTDIR="$pkgdir" install
  make DESTDIR="$pkgdir" install-pkgconfigDATA
}
